﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 隐藏块的管理器.
/// </summary>
public class HideBoardManager : MonoBehaviour
{
    private static HideBoardManager _instance;
    public static HideBoardManager Instance { get { return _instance; } }

    private Dictionary<int, List<HideBoard>> _hideDic;

    private void Awake()
    {
        _instance = this;
        _hideDic = new Dictionary<int, List<HideBoard>>();
        _hideDic.Add(0, new List<HideBoard>());
        _hideDic.Add(1, new List<HideBoard>());
        _hideDic.Add(2, new List<HideBoard>());
        _hideDic.Add(3, new List<HideBoard>());

        //获取场上的所有隐藏板.
        var boards = FindObjectsOfType<HideBoard>();
        Debug.Log("获取到了" + boards.Length + "块隐藏板");
        for (int i = 0; i < boards.Length; i++)
        {
            _hideDic[boards[i].EnableState].Add(boards[i]);
        }
    }

    /// <summary>
    /// 对应状态的激活.
    /// </summary>
    /// <param name="state"></param>
    public void ActivateAll(int state)
    {
        DisableAll();
        for (int i = 0; i < _hideDic[state].Count; i++)
        {
            _hideDic[state][i].Activate();
        }
    }

    private void DisableAll()
    {
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < _hideDic[i].Count; j++)
            {
                _hideDic[i][j].DisableColl();
            }
        }
    }
}
